package com.rc.web.controller;

import com.mybatisflex.core.paginate.Page;
import com.rc.pojo.dto.question.QuestionAddDTO;
import com.rc.pojo.dto.question.QuestionQuery;
import com.rc.pojo.vo.question.QuestionListVO;
import com.rc.pojo.vo.question.QuestionPageVO;
import com.rc.pojo.vo.question.QuestionVO;
import com.rc.web.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/question")
@Api(tags = "互动问题")
@RequiredArgsConstructor
public class QuestionController {
    private final QuestionService questionService;

    @PostMapping
    @ApiOperation("新增互动问题")
    public void add(@Validated @RequestBody QuestionAddDTO dto) {
        questionService.add(dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public void deleteOneById(@PathVariable Long id) {
        questionService.deleteOneById(id);
    }

    @GetMapping("/{id}")
    @ApiOperation("获取id")
    public QuestionVO getOneById(@PathVariable Long id) {
        return questionService.getOneById(id);
    }

    @GetMapping
    @ApiOperation("获取互动界面问题")
    public QuestionListVO getListByPlantId(@ApiParam("植物id") Long plantId, @ApiParam("植物id") Long illId) {
        return questionService.getListByPlantId(plantId, illId);
    }

    @GetMapping("/ill")
    @ApiOperation("病虫害获取互动界面问题")
    public QuestionListVO getListByIllId(@ApiParam("病害id") @RequestParam Long illId) {
        return questionService.getListByIllId(illId);
    }


    @GetMapping("/page")
    @ApiOperation("分页")
    public Page<QuestionPageVO> getPage(QuestionQuery query){
        return questionService.getPage(query);
    }
}
